package com.ruoyi.web.controller.loan.controller;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.loan.service.LoanService;
import com.ruoyi.loan.dto.SelectLoadDto;
import com.ruoyi.loan.service.LoanRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * Author: 廖振辉
 * Date: 2022/4/5
 * Description:
 */
@Controller
@Api(tags = "贷款相关controller")
@RequestMapping("/loan/loan")
public class LoanController {

    @Resource
    private LoanService loanservice;

    @Resource
    private LoanRecordService recordService;

    @GetMapping()
    public String message(){
        String prefix = "loan/loan";
        return prefix + "/loan";
    }

    @GetMapping("/loanApply")
    public String getPage(){
        String prefix = "loan/loan_apply";
        return prefix + "/loan_apply";
    }

    @ApiOperation("批量还款提醒")
    @RequestMapping(value = "/remindRepayment",method = RequestMethod.POST)
    public AjaxResult remindRepayment(@RequestBody List<Integer> userIdList){
        for (Integer userId : userIdList) {
            loanservice.remindRepayment(userId);
        }
        return AjaxResult.success();
    }

    @ApiOperation("上传贷款申请回访录音")
    @ResponseBody
    @RequestMapping(value = "/uploadVoice",method = RequestMethod.POST)
    public AjaxResult uploadVoice(@RequestParam("file") MultipartFile file,Integer loanId){
        loanservice.uploadVoice(file,loanId);
        return AjaxResult.success();
    }

    @ApiOperation("审批助学贷款申请")
    @ResponseBody
    @RequestMapping(value = "/approveLoanApply",method = RequestMethod.POST)
    public AjaxResult approveLoanApply(Integer loanId,String refuseReasons,Integer approve){
        Integer adminId = ShiroUtils.getSysUser().getUserId().intValue();
        loanservice.approveLoanApply(adminId,loanId,refuseReasons,approve);
        return AjaxResult.success();
    }

    /**
     * 查询学生贷款信息
     * @param dto 查询信息
     * @return 贷款信息
     */
    @ResponseBody
    @ApiOperation("查询学生贷款信息")
    @GetMapping("/getLoanList")
    public AjaxResult selectLoadList(SelectLoadDto dto){
        PageInfo pageInfo = recordService.selectLoanList(dto);
        return AjaxResult.success(pageInfo);
    }

    /**
     * 查询学生贷款审核信息
     * @param dto 查询信息
     * @return 贷款信息
     */
    @ResponseBody
    @ApiOperation("查询学生贷款信息")
    @GetMapping("/getVerityLoanList")
    public AjaxResult getVerityLoanList(SelectLoadDto dto){
        PageInfo pageInfo = recordService.getVerityLoanList(dto);
        return AjaxResult.success(pageInfo);
    }


}
